package com.example.wordcardjavaproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wordcardjavaproject.bean.entity.User;
import com.example.wordcardjavaproject.mapper.UserMapper;
import com.example.wordcardjavaproject.service.UserService;
import com.example.wordcardjavaproject.utils.SnowFlake;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public void addUser(User user) {
        user.setId(SnowFlake.nextId());
        userMapper.addUser(user);
    }

    @Override
    public User login(User user) throws Exception {
        User selectUser = userMapper.selectUser(user);
        if (user == null) {
            throw new Exception("找不到该用户或用户名密码错误");
        } else {
            return selectUser;
        }
    }
}
